using System;
using System.Collections.Generic;
using System.Text;

using Forum.Contracts;

namespace Forum.Application
{
    public class ApplicationLogic : IApplication
    {
        private IDataAccess db;


        public ApplicationLogic()
        {
            this.db = new Forum.DataAccess.DataAccessAdapter();
            this.db.Initialize();
        }

        public ApplicationLogic(IDataAccess db)
        {
            this.db = db;
            this.db.Initialize();
        }


        #region IApplication Members
        public void Clear()
        {
            this.db.Clear();
        }


        public Posting[] GetAllPostings()
        {
            return this.db.FindPostingsByParent(null);
        }


        public Posting CreatePosting()
        {
            return new Posting(this.db, null);
        }

        public Posting CreateReply(Posting parent)
        {
            return new Posting(this.db, parent);
        }


        public void StorePosting(Posting posting)
        {
            this.db.StorePosting(posting);
        }
        #endregion


        #region IDisposable Members
        public void Dispose()
        {
            this.db.Dispose();
        }
        #endregion
    }
}
